<?php
class Admini_TaskController extends Uuch_ManageController {
    
    public function init() {
        parent::init();
        $this->appendCss('/admins/css/yundan.css');
        $this->appendCss('/admins/css/common.css');
        $this->appendScript('/admins/js/jquery/jquery-1.7.2.min.js')->appendScript('/js/jquery.validate.min.js')->appendScript('/js/messages_cn.js')->appendScript('/js/uuch.js');
        $this->setTitle("用户任务管理");
        $this->view->type = "system";
    }    
       
    public function indexAction()
    {
        $pagesize = 20;
        $pageindex = $this->getSafeParam('start');
        if (!$pageindex) {
            $pageindex = 0;
        }
        $name = $this->getSafeParam("name");
        $typeid = $this->getSafeParam("typeid");
        $status = $this->getSafeParam("status");
        $taskSearch = new Application_Model_Filter_TaskSearch();
        $taskSearch->name = $name;
        $taskSearch->type = $typeid;
        $taskSearch->status = $status;
        $taskItem = Application_Model_Task::getTaskFileds($taskSearch,$pagesize,$pageindex);
        $this->view->taskAll = $taskItem;
        $this->view->taskList = $taskItem["list"];
        $this->view->name = $name;
        $this->view->typeid = $typeid;
        $this->view->status = $status;
        $this->view->typeAll = Application_Model_Task::getTypeAll();
        $this->view->statusAll = Application_Model_Task::getStatusAll();
        $this->view->type = "system";
        $this->view->stype = 21;
    }
    
    public function addoredittaskAction()
    {
        $id = $this->getSafeParam("id");
        $name = $this->getSafeParam("name");
        $type = $this->getSafeParam("type");
        $score = $this->getSafeParam("score");
        $status = $this->getSafeParam("status");
        $code = $this->getSafeParam("code");
        $taskId = Application_Model_Task::addOrEditTask($id,$name,$type,$score,$status,$code);
        if($taskId != ""){
            $this->json(1);
        } else {
            $this->json(0);
        }
    }
    
    public function deltaskAction()
    {
        $id = $this->getSafeParam("id");
        $taskItem = Application_Model_Task::load($id);
        if($taskItem){
            Application_Model_Operate::addOperate(0, null,  $taskItem->Name, "删除自动任务：".$taskItem->Name, 0);
            $taskItem->delete();
            $this->json(1);
        } else {
            $this->json(0);
        }
    }
    
    public function taskdetailAction()
    {
        $id = $this->getSafeParam("id");
        $taskItem = Application_Model_Task::load($id);
        if($taskItem != null){
            $this->json(array("sj"=>1,"id"=>$taskItem->Id,"name"=>$taskItem->Name,"score"=>$taskItem->Score,"type"=>$taskItem->Type,"status"=>$taskItem->Status,"code"=>$taskItem->Code));
        } else {
            $this->json(array("sj"=>0));
        }
    }
    
    public function completeuserAction()
    {
        $pagesize = 20;
        $pageindex = $this->getSafeParam('start');
        if (!$pageindex) {
            $pageindex = 0;
        }
        $quick = $this->getSafeParam("quick");
        $taskId = $this->getSafeParam("taskid");
        $startTime = $this->getSafeParam("startTime");
        $endTime = $this->getSafeParam("endTime");
        $completeSearch = new Application_Model_Filter_CompleteSearch();
        $completeSearch->quick = $quick;
        $completeSearch->taskId = $taskId;
        $completeSearch->startTime = $startTime;
        $completeSearch->endTime = $endTime;
        $completeItem = Application_Model_TaskComplete::getFileds($completeSearch,$pagesize,$pageindex);
        $this->view->completeAll = $completeItem;
        $this->view->completeList = $completeItem["list"];
        $this->view->taskAll = Application_Model_Task::getAll();
        $this->view->quick = $quick;
        $this->view->taskId = $taskId;
        $this->view->startTime = $startTime;
        $this->view->endTime = $endTime;
        $this->view->type = "system";
        $this->view->stype = 22;
    }
}
